package thread.demo07.test2;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * 解决方案2：使用Future
 * 
 * @author mengzhang6
 *
 */
public class ThreadPoolDemo3 {
	public static void main(String[] args) {

		ExecutorService executorService = Executors.newFixedThreadPool(100);

		for (int i = 1; i < 1000; i++) {
			int index = i;
			Future future = executorService.submit(() -> divTask(200, index));
			try {
				future.get();
			} catch (InterruptedException | ExecutionException e) {
				e.printStackTrace();
			}
		}
		executorService.shutdown();
	}

	private static void divTask(int a, int b) {
		double result = 1.0 * a / b;
		System.out.println(result);
	}
}
